{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tushare as ts\n",
    "import csv\n",
    "import time\n",
    "import pandas as pd\n",
    "pro = ts.pro_api('35d8848b876df93910413e8936c40745d7b7da42553ae73920862cd9')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "start_date = '20200101'\n",
    "end_date = '20200301'\n",
    "ts_code = '000001.SZ'\n",
    "year='2020'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1. 股票数据获取（Tushare）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.1 股票基本信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TS代码</th>\n",
       "      <th>股票代码</th>\n",
       "      <th>股票名称</th>\n",
       "      <th>行业</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>000001</td>\n",
       "      <td>平安银行</td>\n",
       "      <td>银行</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000002.SZ</td>\n",
       "      <td>000002</td>\n",
       "      <td>万科A</td>\n",
       "      <td>全国地产</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000004.SZ</td>\n",
       "      <td>000004</td>\n",
       "      <td>国华网安</td>\n",
       "      <td>软件服务</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>000005</td>\n",
       "      <td>ST星源</td>\n",
       "      <td>环境保护</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000006.SZ</td>\n",
       "      <td>000006</td>\n",
       "      <td>深振业A</td>\n",
       "      <td>区域地产</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        TS代码    股票代码  股票名称    行业\n",
       "0  000001.SZ  000001  平安银行    银行\n",
       "1  000002.SZ  000002   万科A  全国地产\n",
       "2  000004.SZ  000004  国华网安  软件服务\n",
       "3  000005.SZ  000005  ST星源  环境保护\n",
       "4  000006.SZ  000006  深振业A  区域地产"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_basic = pro.stock_basic(list_status='L', fields='ts_code, symbol, name, industry')\n",
    "\n",
    "# 重命名字段（便于后续导入neo4j）\n",
    "basic_rename = {'ts_code': 'TS代码', 'symbol': '股票代码', 'name': '股票名称', 'industry': '行业'}\n",
    "stock_basic.rename(columns=basic_rename, inplace=True)\n",
    "\n",
    "# 保存为stock_basic.csv\n",
    "stock_basic.to_csv('financial_data\\\\stock_basic.csv', encoding='gbk')\n",
    "\n",
    "stock_basic.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.2 股票Top10股东信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>ann_date</th>\n",
       "      <th>end_date</th>\n",
       "      <th>holder_name</th>\n",
       "      <th>hold_amount</th>\n",
       "      <th>hold_ratio</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20200421</td>\n",
       "      <td>20200331</td>\n",
       "      <td>中国平安保险(集团)股份有限公司-集团本级-自有资金</td>\n",
       "      <td>9.618540e+09</td>\n",
       "      <td>49.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20200421</td>\n",
       "      <td>20200331</td>\n",
       "      <td>香港中央结算有限公司(陆股通)</td>\n",
       "      <td>1.669875e+09</td>\n",
       "      <td>8.60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20200421</td>\n",
       "      <td>20200331</td>\n",
       "      <td>中国平安人寿保险股份有限公司-自有资金</td>\n",
       "      <td>1.186100e+09</td>\n",
       "      <td>6.11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20200421</td>\n",
       "      <td>20200331</td>\n",
       "      <td>中国平安人寿保险股份有限公司-传统-普通保险产品</td>\n",
       "      <td>4.404787e+08</td>\n",
       "      <td>2.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20200421</td>\n",
       "      <td>20200331</td>\n",
       "      <td>中国证券金融股份有限公司</td>\n",
       "      <td>4.292327e+08</td>\n",
       "      <td>2.21</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ts_code  ann_date  end_date                 holder_name   hold_amount  \\\n",
       "0  000001.SZ  20200421  20200331  中国平安保险(集团)股份有限公司-集团本级-自有资金  9.618540e+09   \n",
       "1  000001.SZ  20200421  20200331             香港中央结算有限公司(陆股通)  1.669875e+09   \n",
       "2  000001.SZ  20200421  20200331         中国平安人寿保险股份有限公司-自有资金  1.186100e+09   \n",
       "3  000001.SZ  20200421  20200331    中国平安人寿保险股份有限公司-传统-普通保险产品  4.404787e+08   \n",
       "4  000001.SZ  20200421  20200331                中国证券金融股份有限公司  4.292327e+08   \n",
       "\n",
       "   hold_ratio  \n",
       "0       49.56  \n",
       "1        8.60  \n",
       "2        6.11  \n",
       "3        2.27  \n",
       "4        2.21  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "holders = pd.DataFrame(columns=('ts_code', 'ann_date', 'end_date', 'holder_name', 'hold_amount', 'hold_ratio'))\n",
    "\n",
    "top10_holders = pro.top10_holders(ts_code=ts_code, start_date=start_date, end_date=end_date)\n",
    "\n",
    "top10_holders.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.3 股票概念信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "concept_details = pd.DataFrame(columns=('id', 'concept_name', 'ts_code', 'name'))\n",
    "\n",
    "# concept_detail = pro.concept_detail(id='TS0')  # 该接口 TOKEN 受限\n",
    "    \n",
    "# concept_detail.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.4 股票公告信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# notices = pro.anns(ts_code=ts_code, start_date=start_date, end_date=end_date, year=year)  # 该接口 TOKEN 受限\n",
    "\n",
    "# notices.to_csv(\"financial_data\\\\notices\\\\\"+str(code)+\".csv\",encoding='utf_8_sig',index=False)\n",
    "\n",
    "# notices.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.5 财经新闻信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>content</th>\n",
       "      <th>title</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-11-22 10:09:00</td>\n",
       "      <td>【北京：10月末非金融企业贷款增速创历史同期新高 】据中国人民银行营业管理部11月22日披露...</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-11-22 10:08:29</td>\n",
       "      <td>【湖北省积极推动企业向科创板靠拢，年底将向上交所推荐一批优质企业】湖北省上市指导中心相关人士...</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-11-22 10:08:04</td>\n",
       "      <td>【上海：加快专利审查速度 进一步缩短专利授权周期】上海市人民政府发布关于加快本市高新技术企业...</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-11-22 10:04:35</td>\n",
       "      <td>【生意社：稀土价格走势或将上涨】11月20日稀土指数为344点，与上一日持平，较2011年1...</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-11-22 10:03:40</td>\n",
       "      <td>【上海：加快建设具有全球影响力的科技创新中心 做大做强高新技术产业】上海市人民政府发布关于加...</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              datetime                                            content  \\\n",
       "0  2018-11-22 10:09:00  【北京：10月末非金融企业贷款增速创历史同期新高 】据中国人民银行营业管理部11月22日披露...   \n",
       "1  2018-11-22 10:08:29  【湖北省积极推动企业向科创板靠拢，年底将向上交所推荐一批优质企业】湖北省上市指导中心相关人士...   \n",
       "2  2018-11-22 10:08:04  【上海：加快专利审查速度 进一步缩短专利授权周期】上海市人民政府发布关于加快本市高新技术企业...   \n",
       "3  2018-11-22 10:04:35  【生意社：稀土价格走势或将上涨】11月20日稀土指数为344点，与上一日持平，较2011年1...   \n",
       "4  2018-11-22 10:03:40  【上海：加快建设具有全球影响力的科技创新中心 做大做强高新技术产业】上海市人民政府发布关于加...   \n",
       "\n",
       "  title  \n",
       "0        \n",
       "1        \n",
       "2        \n",
       "3        \n",
       "4        "
      ]
     },
     "execution_count": 129,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "news = pro.news(src='sina', start_date='2018-11-21 09:00:00', end_date='2018-11-22 10:10:00')\n",
    "news.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.6 概念信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "# concept = pro.concept()  # 该接口 TOKEN 受限\n",
    "\n",
    "# concept.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.7 沪股通成分和深股通成分信息 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>hs_type</th>\n",
       "      <th>in_date</th>\n",
       "      <th>out_date</th>\n",
       "      <th>is_new</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>601628.SH</td>\n",
       "      <td>SH</td>\n",
       "      <td>20141117</td>\n",
       "      <td>None</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>601099.SH</td>\n",
       "      <td>SH</td>\n",
       "      <td>20141117</td>\n",
       "      <td>None</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>601808.SH</td>\n",
       "      <td>SH</td>\n",
       "      <td>20141117</td>\n",
       "      <td>None</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>601107.SH</td>\n",
       "      <td>SH</td>\n",
       "      <td>20141117</td>\n",
       "      <td>None</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>601880.SH</td>\n",
       "      <td>SH</td>\n",
       "      <td>20141117</td>\n",
       "      <td>None</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ts_code hs_type   in_date out_date is_new\n",
       "0  601628.SH      SH  20141117     None      1\n",
       "1  601099.SH      SH  20141117     None      1\n",
       "2  601808.SH      SH  20141117     None      1\n",
       "3  601107.SH      SH  20141117     None      1\n",
       "4  601880.SH      SH  20141117     None      1"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sh = pro.hs_const(hs_type='SH')  # 获取沪股通成分\n",
    "\n",
    "sz = pro.hs_const(hs_type='SZ')  # 获取深股通成分\n",
    "\n",
    "sh.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.8 股票价格信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>trade_date</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>change</th>\n",
       "      <th>pct_chg</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20200123</td>\n",
       "      <td>15.92</td>\n",
       "      <td>15.92</td>\n",
       "      <td>15.39</td>\n",
       "      <td>15.54</td>\n",
       "      <td>16.09</td>\n",
       "      <td>-0.55</td>\n",
       "      <td>-3.4183</td>\n",
       "      <td>1100592.07</td>\n",
       "      <td>1723394.336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20200122</td>\n",
       "      <td>15.92</td>\n",
       "      <td>16.16</td>\n",
       "      <td>15.71</td>\n",
       "      <td>16.09</td>\n",
       "      <td>16.00</td>\n",
       "      <td>0.09</td>\n",
       "      <td>0.5625</td>\n",
       "      <td>719464.91</td>\n",
       "      <td>1150933.398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20200121</td>\n",
       "      <td>16.34</td>\n",
       "      <td>16.34</td>\n",
       "      <td>15.93</td>\n",
       "      <td>16.00</td>\n",
       "      <td>16.45</td>\n",
       "      <td>-0.45</td>\n",
       "      <td>-2.7356</td>\n",
       "      <td>896603.10</td>\n",
       "      <td>1442171.431</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20200120</td>\n",
       "      <td>16.43</td>\n",
       "      <td>16.61</td>\n",
       "      <td>16.35</td>\n",
       "      <td>16.45</td>\n",
       "      <td>16.39</td>\n",
       "      <td>0.06</td>\n",
       "      <td>0.3661</td>\n",
       "      <td>746074.75</td>\n",
       "      <td>1226464.649</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20200117</td>\n",
       "      <td>16.38</td>\n",
       "      <td>16.55</td>\n",
       "      <td>16.35</td>\n",
       "      <td>16.39</td>\n",
       "      <td>16.33</td>\n",
       "      <td>0.06</td>\n",
       "      <td>0.3674</td>\n",
       "      <td>605436.69</td>\n",
       "      <td>995909.007</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ts_code trade_date   open   high    low  close  pre_close  change  \\\n",
       "0  000001.SZ   20200123  15.92  15.92  15.39  15.54      16.09   -0.55   \n",
       "1  000001.SZ   20200122  15.92  16.16  15.71  16.09      16.00    0.09   \n",
       "2  000001.SZ   20200121  16.34  16.34  15.93  16.00      16.45   -0.45   \n",
       "3  000001.SZ   20200120  16.43  16.61  16.35  16.45      16.39    0.06   \n",
       "4  000001.SZ   20200117  16.38  16.55  16.35  16.39      16.33    0.06   \n",
       "\n",
       "   pct_chg         vol       amount  \n",
       "0  -3.4183  1100592.07  1723394.336  \n",
       "1   0.5625   719464.91  1150933.398  \n",
       "2  -2.7356   896603.10  1442171.431  \n",
       "3   0.3661   746074.75  1226464.649  \n",
       "4   0.3674   605436.69   995909.007  "
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "end_date = '20200201'  # 使用更短数据目的是1.9绘制走势图数值不重叠\n",
    "\n",
    "price = pro.query('daily', ts_code=ts_code, start_date=start_date, end_date=end_date)\n",
    "\n",
    "price.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.9 股票价格走势图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"c3efa850753d482ba3381089121d31fc\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_c3efa850753d482ba3381089121d31fc = echarts.init(\n",
       "                    document.getElementById('c3efa850753d482ba3381089121d31fc'), 'white', {renderer: 'canvas'});\n",
       "                var option_c3efa850753d482ba3381089121d31fc = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"name\": \"\\u6536\\u76d8\\u4ef7\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbol\": \"circle\",\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"20200102\",\n",
       "                    16.87\n",
       "                ],\n",
       "                [\n",
       "                    \"20200103\",\n",
       "                    17.18\n",
       "                ],\n",
       "                [\n",
       "                    \"20200106\",\n",
       "                    17.07\n",
       "                ],\n",
       "                [\n",
       "                    \"20200107\",\n",
       "                    17.15\n",
       "                ],\n",
       "                [\n",
       "                    \"20200108\",\n",
       "                    16.66\n",
       "                ],\n",
       "                [\n",
       "                    \"20200109\",\n",
       "                    16.79\n",
       "                ],\n",
       "                [\n",
       "                    \"20200110\",\n",
       "                    16.69\n",
       "                ],\n",
       "                [\n",
       "                    \"20200113\",\n",
       "                    16.99\n",
       "                ],\n",
       "                [\n",
       "                    \"20200114\",\n",
       "                    16.76\n",
       "                ],\n",
       "                [\n",
       "                    \"20200115\",\n",
       "                    16.52\n",
       "                ],\n",
       "                [\n",
       "                    \"20200116\",\n",
       "                    16.33\n",
       "                ],\n",
       "                [\n",
       "                    \"20200117\",\n",
       "                    16.39\n",
       "                ],\n",
       "                [\n",
       "                    \"20200120\",\n",
       "                    16.45\n",
       "                ],\n",
       "                [\n",
       "                    \"20200121\",\n",
       "                    16.0\n",
       "                ],\n",
       "                [\n",
       "                    \"20200122\",\n",
       "                    16.09\n",
       "                ],\n",
       "                [\n",
       "                    \"20200123\",\n",
       "                    15.54\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u6536\\u76d8\\u4ef7\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u6536\\u76d8\\u4ef7\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"20200102\",\n",
       "                \"20200103\",\n",
       "                \"20200106\",\n",
       "                \"20200107\",\n",
       "                \"20200108\",\n",
       "                \"20200109\",\n",
       "                \"20200110\",\n",
       "                \"20200113\",\n",
       "                \"20200114\",\n",
       "                \"20200115\",\n",
       "                \"20200116\",\n",
       "                \"20200117\",\n",
       "                \"20200120\",\n",
       "                \"20200121\",\n",
       "                \"20200122\",\n",
       "                \"20200123\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u4ef7\\u683c\\u8d70\\u52bf\\u56fe\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_c3efa850753d482ba3381089121d31fc.setOption(option_c3efa850753d482ba3381089121d31fc);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x7ffb145fbc50>"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts.charts import Line\n",
    "from pyecharts import options as opts\n",
    "import numpy as np\n",
    "\n",
    "price = pro.query('daily', ts_code=ts_code, start_date=start_date, end_date=end_date)\n",
    "(\n",
    "    Line()\n",
    "    .add_xaxis(xaxis_data=list(price['trade_date'])[::-1])\n",
    "    .add_yaxis(series_name=\"收盘价\",y_axis=list(price['close'])[::-1],symbol=\"circle\")\n",
    "#     .add_yaxis(series_name=\"开盘价\",y_axis=list(price['open'])[::-1],symbol=\"circle\")\n",
    "#     .add_yaxis(series_name=\"最高价\",y_axis=list(price['high'])[::-1],symbol=\"circle\")\n",
    "#     .add_yaxis(series_name=\"最低价\",y_axis=list(price['low'])[::-1],symbol=\"circle\")\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"价格走势图\"))\n",
    "    .render_notebook()\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.10 基本面数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>chairman</th>\n",
       "      <th>manager</th>\n",
       "      <th>secretary</th>\n",
       "      <th>reg_capital</th>\n",
       "      <th>setup_date</th>\n",
       "      <th>province</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>300952.SZ</td>\n",
       "      <td>王咸华</td>\n",
       "      <td>王咸华</td>\n",
       "      <td>张武芬</td>\n",
       "      <td>14492.7653</td>\n",
       "      <td>20040415</td>\n",
       "      <td>江苏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>300268.SZ</td>\n",
       "      <td>汤捷</td>\n",
       "      <td>汤捷</td>\n",
       "      <td>杨振刚</td>\n",
       "      <td>17420.0000</td>\n",
       "      <td>20030508</td>\n",
       "      <td>湖南</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>300447.SZ</td>\n",
       "      <td>陈祥楼</td>\n",
       "      <td>何亮</td>\n",
       "      <td>孙璐</td>\n",
       "      <td>29106.9255</td>\n",
       "      <td>20010929</td>\n",
       "      <td>江苏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>300451.SZ</td>\n",
       "      <td>葛航</td>\n",
       "      <td>张吕峥</td>\n",
       "      <td>胡燕</td>\n",
       "      <td>119260.8104</td>\n",
       "      <td>19971210</td>\n",
       "      <td>浙江</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>002531.SZ</td>\n",
       "      <td>严俊旭</td>\n",
       "      <td>严俊旭</td>\n",
       "      <td>朱彬</td>\n",
       "      <td>180250.9062</td>\n",
       "      <td>20050118</td>\n",
       "      <td>江苏</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ts_code chairman manager secretary  reg_capital setup_date province\n",
       "0  300952.SZ      王咸华     王咸华       张武芬   14492.7653   20040415       江苏\n",
       "1  300268.SZ       汤捷      汤捷       杨振刚   17420.0000   20030508       湖南\n",
       "2  300447.SZ      陈祥楼      何亮        孙璐   29106.9255   20010929       江苏\n",
       "3  300451.SZ       葛航     张吕峥        胡燕  119260.8104   19971210       浙江\n",
       "4  002531.SZ      严俊旭     严俊旭        朱彬  180250.9062   20050118       江苏"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_company = pro.stock_company(exchange='SZSE', fields='ts_code,chairman,manager,secretary,reg_capital,setup_date,province')\n",
    "stock_company.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>type</th>\n",
       "      <th>date</th>\n",
       "      <th>url</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>平安银行：平安银行股份有限公司2020年年度权益分派实施公告2021-05-07</td>\n",
       "      <td>临时公告</td>\n",
       "      <td>2021-05-07</td>\n",
       "      <td>http://vip.stock.finance.sina.com.cn/corp/view...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>平安银行：2021年第一季度报告全文</td>\n",
       "      <td>一季度报告</td>\n",
       "      <td>2021-04-21</td>\n",
       "      <td>http://vip.stock.finance.sina.com.cn/corp/view...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>平安银行：一季报监事会决议公告</td>\n",
       "      <td>临时公告</td>\n",
       "      <td>2021-04-21</td>\n",
       "      <td>http://vip.stock.finance.sina.com.cn/corp/view...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>平安银行：一季报董事会决议公告</td>\n",
       "      <td>临时公告</td>\n",
       "      <td>2021-04-21</td>\n",
       "      <td>http://vip.stock.finance.sina.com.cn/corp/view...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>平安银行：2021年第一季度报告正文</td>\n",
       "      <td>一季度报告（摘要）</td>\n",
       "      <td>2021-04-21</td>\n",
       "      <td>http://vip.stock.finance.sina.com.cn/corp/view...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                      title       type        date  \\\n",
       "0  平安银行：平安银行股份有限公司2020年年度权益分派实施公告2021-05-07       临时公告  2021-05-07   \n",
       "1                        平安银行：2021年第一季度报告全文      一季度报告  2021-04-21   \n",
       "2                           平安银行：一季报监事会决议公告       临时公告  2021-04-21   \n",
       "3                           平安银行：一季报董事会决议公告       临时公告  2021-04-21   \n",
       "4                        平安银行：2021年第一季度报告正文  一季度报告（摘要）  2021-04-21   \n",
       "\n",
       "                                                 url  \n",
       "0  http://vip.stock.finance.sina.com.cn/corp/view...  \n",
       "1  http://vip.stock.finance.sina.com.cn/corp/view...  \n",
       "2  http://vip.stock.finance.sina.com.cn/corp/view...  \n",
       "3  http://vip.stock.finance.sina.com.cn/corp/view...  \n",
       "4  http://vip.stock.finance.sina.com.cn/corp/view...  "
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import tushare as ts\n",
    "ts.get_notices(\"000001\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>ptime</th>\n",
       "      <th>rcounts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>机构减仓或在战役性转移</td>\n",
       "      <td>05月07日 14:57</td>\n",
       "      <td>360.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>170家电子行业公司发布年度业绩预告</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>券商开户专属通道：新客专享理财福利多多</td>\n",
       "      <td></td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>热门股票如何选择盘中介入点</td>\n",
       "      <td>05月07日 07:40</td>\n",
       "      <td>419.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>节后综合症再现 依然不乏结构性机会</td>\n",
       "      <td>05月07日 08:03</td>\n",
       "      <td>507.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 title         ptime  rcounts\n",
       "0          机构减仓或在战役性转移  05月07日 14:57    360.0\n",
       "1   170家电子行业公司发布年度业绩预告                    0.0\n",
       "2  券商开户专属通道：新客专享理财福利多多                    0.0\n",
       "3        热门股票如何选择盘中介入点  05月07日 07:40    419.0\n",
       "4    节后综合症再现 依然不乏结构性机会  05月07日 08:03    507.0"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ts.guba_sina().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "本接口即将停止更新，请尽快使用Pro版接口：https://tushare.pro/document/2\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>close</th>\n",
       "      <th>low</th>\n",
       "      <th>volume</th>\n",
       "      <th>price_change</th>\n",
       "      <th>p_change</th>\n",
       "      <th>ma5</th>\n",
       "      <th>ma10</th>\n",
       "      <th>ma20</th>\n",
       "      <th>v_ma5</th>\n",
       "      <th>v_ma10</th>\n",
       "      <th>v_ma20</th>\n",
       "      <th>turnover</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-05-07</th>\n",
       "      <td>23.67</td>\n",
       "      <td>24.30</td>\n",
       "      <td>24.05</td>\n",
       "      <td>23.39</td>\n",
       "      <td>802214.25</td>\n",
       "      <td>0.55</td>\n",
       "      <td>2.34</td>\n",
       "      <td>23.556</td>\n",
       "      <td>23.294</td>\n",
       "      <td>22.153</td>\n",
       "      <td>614633.11</td>\n",
       "      <td>766603.84</td>\n",
       "      <td>700531.86</td>\n",
       "      <td>0.41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-06</th>\n",
       "      <td>23.10</td>\n",
       "      <td>23.70</td>\n",
       "      <td>23.50</td>\n",
       "      <td>23.10</td>\n",
       "      <td>500295.19</td>\n",
       "      <td>0.21</td>\n",
       "      <td>0.90</td>\n",
       "      <td>23.334</td>\n",
       "      <td>23.058</td>\n",
       "      <td>22.034</td>\n",
       "      <td>548276.55</td>\n",
       "      <td>769859.69</td>\n",
       "      <td>680476.29</td>\n",
       "      <td>0.26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-30</th>\n",
       "      <td>23.35</td>\n",
       "      <td>23.49</td>\n",
       "      <td>23.29</td>\n",
       "      <td>23.01</td>\n",
       "      <td>561981.31</td>\n",
       "      <td>-0.30</td>\n",
       "      <td>-1.27</td>\n",
       "      <td>23.222</td>\n",
       "      <td>22.823</td>\n",
       "      <td>21.934</td>\n",
       "      <td>622701.05</td>\n",
       "      <td>831058.44</td>\n",
       "      <td>684515.71</td>\n",
       "      <td>0.29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-29</th>\n",
       "      <td>23.34</td>\n",
       "      <td>23.71</td>\n",
       "      <td>23.59</td>\n",
       "      <td>23.11</td>\n",
       "      <td>614836.88</td>\n",
       "      <td>0.24</td>\n",
       "      <td>1.03</td>\n",
       "      <td>23.222</td>\n",
       "      <td>22.520</td>\n",
       "      <td>21.859</td>\n",
       "      <td>674950.82</td>\n",
       "      <td>847860.13</td>\n",
       "      <td>683639.09</td>\n",
       "      <td>0.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-28</th>\n",
       "      <td>23.29</td>\n",
       "      <td>23.45</td>\n",
       "      <td>23.35</td>\n",
       "      <td>22.78</td>\n",
       "      <td>593837.94</td>\n",
       "      <td>0.41</td>\n",
       "      <td>1.79</td>\n",
       "      <td>23.100</td>\n",
       "      <td>22.197</td>\n",
       "      <td>21.780</td>\n",
       "      <td>717922.23</td>\n",
       "      <td>859962.95</td>\n",
       "      <td>691748.65</td>\n",
       "      <td>0.31</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             open   high  close    low     volume  price_change  p_change  \\\n",
       "date                                                                        \n",
       "2021-05-07  23.67  24.30  24.05  23.39  802214.25          0.55      2.34   \n",
       "2021-05-06  23.10  23.70  23.50  23.10  500295.19          0.21      0.90   \n",
       "2021-04-30  23.35  23.49  23.29  23.01  561981.31         -0.30     -1.27   \n",
       "2021-04-29  23.34  23.71  23.59  23.11  614836.88          0.24      1.03   \n",
       "2021-04-28  23.29  23.45  23.35  22.78  593837.94          0.41      1.79   \n",
       "\n",
       "               ma5    ma10    ma20      v_ma5     v_ma10     v_ma20  turnover  \n",
       "date                                                                           \n",
       "2021-05-07  23.556  23.294  22.153  614633.11  766603.84  700531.86      0.41  \n",
       "2021-05-06  23.334  23.058  22.034  548276.55  769859.69  680476.29      0.26  \n",
       "2021-04-30  23.222  22.823  21.934  622701.05  831058.44  684515.71      0.29  \n",
       "2021-04-29  23.222  22.520  21.859  674950.82  847860.13  683639.09      0.32  \n",
       "2021-04-28  23.100  22.197  21.780  717922.23  859962.95  691748.65      0.31  "
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ts.get_hist_data(\"000001\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "本接口即将停止更新，请尽快使用Pro版接口：https://tushare.pro/document/2\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>close</th>\n",
       "      <th>low</th>\n",
       "      <th>volume</th>\n",
       "      <th>price_change</th>\n",
       "      <th>p_change</th>\n",
       "      <th>ma5</th>\n",
       "      <th>ma10</th>\n",
       "      <th>ma20</th>\n",
       "      <th>v_ma5</th>\n",
       "      <th>v_ma10</th>\n",
       "      <th>v_ma20</th>\n",
       "      <th>turnover</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-05-07</th>\n",
       "      <td>23.10</td>\n",
       "      <td>24.30</td>\n",
       "      <td>24.05</td>\n",
       "      <td>23.10</td>\n",
       "      <td>1302509.50</td>\n",
       "      <td>0.76</td>\n",
       "      <td>3.26</td>\n",
       "      <td>22.438</td>\n",
       "      <td>21.912</td>\n",
       "      <td>21.823</td>\n",
       "      <td>2882347.97</td>\n",
       "      <td>3893787.24</td>\n",
       "      <td>4866394.11</td>\n",
       "      <td>0.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-30</th>\n",
       "      <td>23.87</td>\n",
       "      <td>24.23</td>\n",
       "      <td>23.29</td>\n",
       "      <td>22.78</td>\n",
       "      <td>3113505.25</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>21.928</td>\n",
       "      <td>21.645</td>\n",
       "      <td>21.538</td>\n",
       "      <td>3307222.47</td>\n",
       "      <td>4560954.59</td>\n",
       "      <td>5004209.48</td>\n",
       "      <td>1.60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-23</th>\n",
       "      <td>20.03</td>\n",
       "      <td>23.65</td>\n",
       "      <td>23.29</td>\n",
       "      <td>19.91</td>\n",
       "      <td>5197079.00</td>\n",
       "      <td>3.03</td>\n",
       "      <td>14.96</td>\n",
       "      <td>21.498</td>\n",
       "      <td>21.701</td>\n",
       "      <td>21.300</td>\n",
       "      <td>3544311.92</td>\n",
       "      <td>4492385.46</td>\n",
       "      <td>5036850.99</td>\n",
       "      <td>2.68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-16</th>\n",
       "      <td>21.51</td>\n",
       "      <td>21.51</td>\n",
       "      <td>20.26</td>\n",
       "      <td>19.81</td>\n",
       "      <td>3097949.00</td>\n",
       "      <td>-1.04</td>\n",
       "      <td>-4.88</td>\n",
       "      <td>20.934</td>\n",
       "      <td>21.754</td>\n",
       "      <td>21.100</td>\n",
       "      <td>3492326.92</td>\n",
       "      <td>4367200.06</td>\n",
       "      <td>5044014.37</td>\n",
       "      <td>1.60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-09</th>\n",
       "      <td>21.55</td>\n",
       "      <td>22.09</td>\n",
       "      <td>21.30</td>\n",
       "      <td>21.08</td>\n",
       "      <td>1700697.12</td>\n",
       "      <td>-0.20</td>\n",
       "      <td>-0.93</td>\n",
       "      <td>21.178</td>\n",
       "      <td>22.221</td>\n",
       "      <td>21.072</td>\n",
       "      <td>3922926.32</td>\n",
       "      <td>4865955.41</td>\n",
       "      <td>5078637.83</td>\n",
       "      <td>0.88</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             open   high  close    low      volume  price_change  p_change  \\\n",
       "date                                                                         \n",
       "2021-05-07  23.10  24.30  24.05  23.10  1302509.50          0.76      3.26   \n",
       "2021-04-30  23.87  24.23  23.29  22.78  3113505.25          0.00      0.00   \n",
       "2021-04-23  20.03  23.65  23.29  19.91  5197079.00          3.03     14.96   \n",
       "2021-04-16  21.51  21.51  20.26  19.81  3097949.00         -1.04     -4.88   \n",
       "2021-04-09  21.55  22.09  21.30  21.08  1700697.12         -0.20     -0.93   \n",
       "\n",
       "               ma5    ma10    ma20       v_ma5      v_ma10      v_ma20  \\\n",
       "date                                                                     \n",
       "2021-05-07  22.438  21.912  21.823  2882347.97  3893787.24  4866394.11   \n",
       "2021-04-30  21.928  21.645  21.538  3307222.47  4560954.59  5004209.48   \n",
       "2021-04-23  21.498  21.701  21.300  3544311.92  4492385.46  5036850.99   \n",
       "2021-04-16  20.934  21.754  21.100  3492326.92  4367200.06  5044014.37   \n",
       "2021-04-09  21.178  22.221  21.072  3922926.32  4865955.41  5078637.83   \n",
       "\n",
       "            turnover  \n",
       "date                  \n",
       "2021-05-07      0.67  \n",
       "2021-04-30      1.60  \n",
       "2021-04-23      2.68  \n",
       "2021-04-16      1.60  \n",
       "2021-04-09      0.88  "
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ts.get_hist_data(\"000001\",ktype=\"w\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "本接口即将停止更新，请尽快使用Pro版接口：https://tushare.pro/document/2\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>close</th>\n",
       "      <th>low</th>\n",
       "      <th>volume</th>\n",
       "      <th>price_change</th>\n",
       "      <th>p_change</th>\n",
       "      <th>ma5</th>\n",
       "      <th>ma10</th>\n",
       "      <th>ma20</th>\n",
       "      <th>v_ma5</th>\n",
       "      <th>v_ma10</th>\n",
       "      <th>v_ma20</th>\n",
       "      <th>turnover</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-05-07</th>\n",
       "      <td>23.10</td>\n",
       "      <td>24.30</td>\n",
       "      <td>24.05</td>\n",
       "      <td>23.10</td>\n",
       "      <td>1302509.5</td>\n",
       "      <td>0.76</td>\n",
       "      <td>3.26</td>\n",
       "      <td>22.764</td>\n",
       "      <td>20.090</td>\n",
       "      <td>17.241</td>\n",
       "      <td>17859144.9</td>\n",
       "      <td>20308849.85</td>\n",
       "      <td>20748658.73</td>\n",
       "      <td>0.67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-30</th>\n",
       "      <td>22.08</td>\n",
       "      <td>24.23</td>\n",
       "      <td>23.29</td>\n",
       "      <td>19.81</td>\n",
       "      <td>14234763.0</td>\n",
       "      <td>1.28</td>\n",
       "      <td>5.82</td>\n",
       "      <td>21.822</td>\n",
       "      <td>19.019</td>\n",
       "      <td>16.818</td>\n",
       "      <td>21521885.8</td>\n",
       "      <td>24854576.10</td>\n",
       "      <td>21952860.65</td>\n",
       "      <td>7.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-03-31</th>\n",
       "      <td>21.54</td>\n",
       "      <td>23.49</td>\n",
       "      <td>22.01</td>\n",
       "      <td>20.28</td>\n",
       "      <td>23400600.0</td>\n",
       "      <td>0.63</td>\n",
       "      <td>2.95</td>\n",
       "      <td>21.112</td>\n",
       "      <td>17.970</td>\n",
       "      <td>16.361</td>\n",
       "      <td>22789929.6</td>\n",
       "      <td>25258599.60</td>\n",
       "      <td>22737767.70</td>\n",
       "      <td>12.06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-02-26</th>\n",
       "      <td>23.00</td>\n",
       "      <td>25.31</td>\n",
       "      <td>21.38</td>\n",
       "      <td>21.21</td>\n",
       "      <td>22432726.0</td>\n",
       "      <td>-1.71</td>\n",
       "      <td>-7.41</td>\n",
       "      <td>20.260</td>\n",
       "      <td>17.069</td>\n",
       "      <td>15.967</td>\n",
       "      <td>22277667.2</td>\n",
       "      <td>24135001.50</td>\n",
       "      <td>22393905.60</td>\n",
       "      <td>11.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-01-29</th>\n",
       "      <td>19.10</td>\n",
       "      <td>23.54</td>\n",
       "      <td>23.09</td>\n",
       "      <td>17.80</td>\n",
       "      <td>27925126.0</td>\n",
       "      <td>3.75</td>\n",
       "      <td>19.39</td>\n",
       "      <td>19.018</td>\n",
       "      <td>16.324</td>\n",
       "      <td>15.587</td>\n",
       "      <td>22094764.0</td>\n",
       "      <td>23598847.10</td>\n",
       "      <td>22103348.45</td>\n",
       "      <td>14.39</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             open   high  close    low      volume  price_change  p_change  \\\n",
       "date                                                                         \n",
       "2021-05-07  23.10  24.30  24.05  23.10   1302509.5          0.76      3.26   \n",
       "2021-04-30  22.08  24.23  23.29  19.81  14234763.0          1.28      5.82   \n",
       "2021-03-31  21.54  23.49  22.01  20.28  23400600.0          0.63      2.95   \n",
       "2021-02-26  23.00  25.31  21.38  21.21  22432726.0         -1.71     -7.41   \n",
       "2021-01-29  19.10  23.54  23.09  17.80  27925126.0          3.75     19.39   \n",
       "\n",
       "               ma5    ma10    ma20       v_ma5       v_ma10       v_ma20  \\\n",
       "date                                                                       \n",
       "2021-05-07  22.764  20.090  17.241  17859144.9  20308849.85  20748658.73   \n",
       "2021-04-30  21.822  19.019  16.818  21521885.8  24854576.10  21952860.65   \n",
       "2021-03-31  21.112  17.970  16.361  22789929.6  25258599.60  22737767.70   \n",
       "2021-02-26  20.260  17.069  15.967  22277667.2  24135001.50  22393905.60   \n",
       "2021-01-29  19.018  16.324  15.587  22094764.0  23598847.10  22103348.45   \n",
       "\n",
       "            turnover  \n",
       "date                  \n",
       "2021-05-07      0.67  \n",
       "2021-04-30      7.34  \n",
       "2021-03-31     12.06  \n",
       "2021-02-26     11.56  \n",
       "2021-01-29     14.39  "
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ts.get_hist_data(\"000001\",ktype=\"m\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "本接口即将停止更新，请尽快使用Pro版接口：https://tushare.pro/document/2\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>close</th>\n",
       "      <th>low</th>\n",
       "      <th>volume</th>\n",
       "      <th>price_change</th>\n",
       "      <th>p_change</th>\n",
       "      <th>ma5</th>\n",
       "      <th>ma10</th>\n",
       "      <th>ma20</th>\n",
       "      <th>v_ma5</th>\n",
       "      <th>v_ma10</th>\n",
       "      <th>v_ma20</th>\n",
       "      <th>turnover</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-05-07 15:00:00</th>\n",
       "      <td>24.01</td>\n",
       "      <td>24.03</td>\n",
       "      <td>24.01</td>\n",
       "      <td>23.98</td>\n",
       "      <td>14157.80</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>24.028</td>\n",
       "      <td>23.998</td>\n",
       "      <td>24.0555</td>\n",
       "      <td>13524.9</td>\n",
       "      <td>12686.8</td>\n",
       "      <td>11663.7</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-07 14:55:00</th>\n",
       "      <td>24.03</td>\n",
       "      <td>24.04</td>\n",
       "      <td>24.01</td>\n",
       "      <td>23.96</td>\n",
       "      <td>14808.00</td>\n",
       "      <td>-0.02</td>\n",
       "      <td>-0.08</td>\n",
       "      <td>24.024</td>\n",
       "      <td>24.002</td>\n",
       "      <td>24.0630</td>\n",
       "      <td>12897.5</td>\n",
       "      <td>13060.2</td>\n",
       "      <td>11526.3</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-07 14:50:00</th>\n",
       "      <td>24.08</td>\n",
       "      <td>24.10</td>\n",
       "      <td>24.02</td>\n",
       "      <td>23.96</td>\n",
       "      <td>20615.30</td>\n",
       "      <td>-0.06</td>\n",
       "      <td>-0.25</td>\n",
       "      <td>23.998</td>\n",
       "      <td>24.011</td>\n",
       "      <td>24.0670</td>\n",
       "      <td>12849.7</td>\n",
       "      <td>13332.0</td>\n",
       "      <td>11336.4</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-07 14:45:00</th>\n",
       "      <td>24.01</td>\n",
       "      <td>24.08</td>\n",
       "      <td>24.08</td>\n",
       "      <td>24.01</td>\n",
       "      <td>9387.44</td>\n",
       "      <td>0.07</td>\n",
       "      <td>0.29</td>\n",
       "      <td>23.990</td>\n",
       "      <td>24.012</td>\n",
       "      <td>24.0680</td>\n",
       "      <td>10501.1</td>\n",
       "      <td>12905.3</td>\n",
       "      <td>11421.0</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-07 14:40:00</th>\n",
       "      <td>24.00</td>\n",
       "      <td>24.03</td>\n",
       "      <td>24.02</td>\n",
       "      <td>23.95</td>\n",
       "      <td>8656.08</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.08</td>\n",
       "      <td>23.978</td>\n",
       "      <td>24.012</td>\n",
       "      <td>24.0655</td>\n",
       "      <td>11153.4</td>\n",
       "      <td>12820.4</td>\n",
       "      <td>11752.8</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      open   high  close    low    volume  price_change  \\\n",
       "date                                                                      \n",
       "2021-05-07 15:00:00  24.01  24.03  24.01  23.98  14157.80          0.00   \n",
       "2021-05-07 14:55:00  24.03  24.04  24.01  23.96  14808.00         -0.02   \n",
       "2021-05-07 14:50:00  24.08  24.10  24.02  23.96  20615.30         -0.06   \n",
       "2021-05-07 14:45:00  24.01  24.08  24.08  24.01   9387.44          0.07   \n",
       "2021-05-07 14:40:00  24.00  24.03  24.02  23.95   8656.08          0.02   \n",
       "\n",
       "                     p_change     ma5    ma10     ma20    v_ma5   v_ma10  \\\n",
       "date                                                                       \n",
       "2021-05-07 15:00:00      0.00  24.028  23.998  24.0555  13524.9  12686.8   \n",
       "2021-05-07 14:55:00     -0.08  24.024  24.002  24.0630  12897.5  13060.2   \n",
       "2021-05-07 14:50:00     -0.25  23.998  24.011  24.0670  12849.7  13332.0   \n",
       "2021-05-07 14:45:00      0.29  23.990  24.012  24.0680  10501.1  12905.3   \n",
       "2021-05-07 14:40:00      0.08  23.978  24.012  24.0655  11153.4  12820.4   \n",
       "\n",
       "                      v_ma20  turnover  \n",
       "date                                    \n",
       "2021-05-07 15:00:00  11663.7      0.01  \n",
       "2021-05-07 14:55:00  11526.3      0.01  \n",
       "2021-05-07 14:50:00  11336.4      0.01  \n",
       "2021-05-07 14:45:00  11421.0      0.01  \n",
       "2021-05-07 14:40:00  11752.8      0.01  "
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ts.get_hist_data(\"000001\",ktype=\"5\").head()  # 5min (15,30,60)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "本接口即将停止更新，请尽快使用Pro版接口：https://tushare.pro/document/2\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>close</th>\n",
       "      <th>low</th>\n",
       "      <th>volume</th>\n",
       "      <th>price_change</th>\n",
       "      <th>p_change</th>\n",
       "      <th>ma5</th>\n",
       "      <th>ma10</th>\n",
       "      <th>ma20</th>\n",
       "      <th>v_ma5</th>\n",
       "      <th>v_ma10</th>\n",
       "      <th>v_ma20</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-05-07</th>\n",
       "      <td>3021.87</td>\n",
       "      <td>3026.85</td>\n",
       "      <td>2910.41</td>\n",
       "      <td>2910.41</td>\n",
       "      <td>14489343.0</td>\n",
       "      <td>-104.40</td>\n",
       "      <td>-3.46</td>\n",
       "      <td>3023.724</td>\n",
       "      <td>2992.490</td>\n",
       "      <td>2898.924</td>\n",
       "      <td>16444300.8</td>\n",
       "      <td>16648376.3</td>\n",
       "      <td>15426893.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-05-06</th>\n",
       "      <td>3059.58</td>\n",
       "      <td>3059.58</td>\n",
       "      <td>3014.81</td>\n",
       "      <td>2961.99</td>\n",
       "      <td>16552269.0</td>\n",
       "      <td>-76.59</td>\n",
       "      <td>-2.48</td>\n",
       "      <td>3038.848</td>\n",
       "      <td>2991.060</td>\n",
       "      <td>2894.984</td>\n",
       "      <td>16974533.4</td>\n",
       "      <td>16827430.9</td>\n",
       "      <td>15346704.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-30</th>\n",
       "      <td>3040.65</td>\n",
       "      <td>3110.16</td>\n",
       "      <td>3091.40</td>\n",
       "      <td>3037.31</td>\n",
       "      <td>16606502.0</td>\n",
       "      <td>39.98</td>\n",
       "      <td>1.31</td>\n",
       "      <td>3029.766</td>\n",
       "      <td>2979.452</td>\n",
       "      <td>2886.855</td>\n",
       "      <td>17752532.8</td>\n",
       "      <td>17050663.6</td>\n",
       "      <td>15277921.70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-29</th>\n",
       "      <td>3053.74</td>\n",
       "      <td>3068.60</td>\n",
       "      <td>3051.42</td>\n",
       "      <td>3014.55</td>\n",
       "      <td>16647988.0</td>\n",
       "      <td>0.84</td>\n",
       "      <td>0.03</td>\n",
       "      <td>3010.384</td>\n",
       "      <td>2948.649</td>\n",
       "      <td>2873.055</td>\n",
       "      <td>17834241.6</td>\n",
       "      <td>16717391.8</td>\n",
       "      <td>15101499.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-04-28</th>\n",
       "      <td>2990.70</td>\n",
       "      <td>3052.04</td>\n",
       "      <td>3050.58</td>\n",
       "      <td>2980.65</td>\n",
       "      <td>17925402.0</td>\n",
       "      <td>64.55</td>\n",
       "      <td>2.16</td>\n",
       "      <td>2987.978</td>\n",
       "      <td>2922.571</td>\n",
       "      <td>2858.409</td>\n",
       "      <td>17635713.4</td>\n",
       "      <td>16185039.8</td>\n",
       "      <td>14900826.45</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               open     high    close      low      volume  price_change  \\\n",
       "date                                                                       \n",
       "2021-05-07  3021.87  3026.85  2910.41  2910.41  14489343.0       -104.40   \n",
       "2021-05-06  3059.58  3059.58  3014.81  2961.99  16552269.0        -76.59   \n",
       "2021-04-30  3040.65  3110.16  3091.40  3037.31  16606502.0         39.98   \n",
       "2021-04-29  3053.74  3068.60  3051.42  3014.55  16647988.0          0.84   \n",
       "2021-04-28  2990.70  3052.04  3050.58  2980.65  17925402.0         64.55   \n",
       "\n",
       "            p_change       ma5      ma10      ma20       v_ma5      v_ma10  \\\n",
       "date                                                                         \n",
       "2021-05-07     -3.46  3023.724  2992.490  2898.924  16444300.8  16648376.3   \n",
       "2021-05-06     -2.48  3038.848  2991.060  2894.984  16974533.4  16827430.9   \n",
       "2021-04-30      1.31  3029.766  2979.452  2886.855  17752532.8  17050663.6   \n",
       "2021-04-29      0.03  3010.384  2948.649  2873.055  17834241.6  16717391.8   \n",
       "2021-04-28      2.16  2987.978  2922.571  2858.409  17635713.4  16185039.8   \n",
       "\n",
       "                 v_ma20  \n",
       "date                     \n",
       "2021-05-07  15426893.45  \n",
       "2021-05-06  15346704.55  \n",
       "2021-04-30  15277921.70  \n",
       "2021-04-29  15101499.00  \n",
       "2021-04-28  14900826.45  "
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# sh上证指数； sz深圳成指； hs300沪深300； sz50上证50； zxb中小板指数； cyb创业板指数\n",
    "ts.get_hist_data(\"cyb\").head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.股票数据获取（巨宽数据源）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "from jqdatasdk import *\n",
    "\n",
    "auth('18280180192', 'Tencent123')  # 请自行前往 https://www.joinquant.com/ 免费申请TOKEN\n",
    "\n",
    "security = '000300.XSHG'\n",
    "start_date = '2020-01-01'\n",
    "end_date = '2020-03-01'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>volume</th>\n",
       "      <th>money</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2020-01-02</th>\n",
       "      <td>4121.35</td>\n",
       "      <td>4152.24</td>\n",
       "      <td>4172.66</td>\n",
       "      <td>4121.35</td>\n",
       "      <td>1.821168e+10</td>\n",
       "      <td>2.701055e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-03</th>\n",
       "      <td>4161.22</td>\n",
       "      <td>4144.96</td>\n",
       "      <td>4164.30</td>\n",
       "      <td>4131.86</td>\n",
       "      <td>1.428262e+10</td>\n",
       "      <td>2.152163e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-06</th>\n",
       "      <td>4120.52</td>\n",
       "      <td>4129.30</td>\n",
       "      <td>4170.64</td>\n",
       "      <td>4102.38</td>\n",
       "      <td>1.753100e+10</td>\n",
       "      <td>2.501821e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-07</th>\n",
       "      <td>4137.40</td>\n",
       "      <td>4160.23</td>\n",
       "      <td>4161.25</td>\n",
       "      <td>4135.10</td>\n",
       "      <td>1.394890e+10</td>\n",
       "      <td>1.963891e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-08</th>\n",
       "      <td>4139.63</td>\n",
       "      <td>4112.32</td>\n",
       "      <td>4149.81</td>\n",
       "      <td>4101.98</td>\n",
       "      <td>1.675858e+10</td>\n",
       "      <td>2.124063e+11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               open    close     high      low        volume         money\n",
       "2020-01-02  4121.35  4152.24  4172.66  4121.35  1.821168e+10  2.701055e+11\n",
       "2020-01-03  4161.22  4144.96  4164.30  4131.86  1.428262e+10  2.152163e+11\n",
       "2020-01-06  4120.52  4129.30  4170.64  4102.38  1.753100e+10  2.501821e+11\n",
       "2020-01-07  4137.40  4160.23  4161.25  4135.10  1.394890e+10  1.963891e+11\n",
       "2020-01-08  4139.63  4112.32  4149.81  4101.98  1.675858e+10  2.124063e+11"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# security 股票代码\n",
    "# frequency 时间粒度（1d=日）\n",
    "# skip_paused 是否跳过缺失交易数据时间点\n",
    "stock_price = get_price(security=security, start_date=start_date, end_date=end_date, frequency='1d',skip_paused=False)\n",
    "\n",
    "stock_price.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
